package net;

import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;

public class URLDemo {
	public static void main(String[] args) {
		try {
			URL url = new URL("http", "news.qq.com", 80, "/a/20130629/006444.htm");
			InputStream input = url.openStream();
			Scanner scan = new Scanner(input);
			scan.useDelimiter("\n");
			while(scan.hasNext())
			{
				//System.out.println(scan.next());
				scan.next();
			}
			
			
			
			URL url2 = new URL("http://www.google.com");
			URLConnection urlConnection = url2.openConnection();
			System.out.println(urlConnection.getContentLength());
			String str = urlConnection.getContentType();
			str = str.substring(str.indexOf("=") + 1, str.length());
			
			System.out.println(str);
			System.out.println(urlConnection.getContentEncoding());
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
